package com.yanqu.road.server.cmd.building;

import com.yanqu.road.pb.building.BuildingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BuildingModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_BUILDING_UPGRADE, desc = "店铺升级")
public class BuildingUpgradeCmd extends AbstractCommand {

	private int buildingId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BuildingProto.BuildingReqMsg reqMsg = BuildingProto.BuildingReqMsg.parseFrom(packet.getBytes());
		buildingId = reqMsg.getBuildingId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(BuildingModule.class).buildingUpgrade(buildingId);
	}

	@Override
	public void sendData(GamePlayer player) {
		BuildingProto.BuildingRespMsg.Builder respMsg = BuildingProto.BuildingRespMsg.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_BUILDING_UPGRADE, respMsg);
	}

}
